<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="楼盘名称">
        <el-input v-model="querys.name" placeholder="楼盘名称"></el-input>
      </el-form-item>
      <el-form-item label="物业类型">
        <el-input v-model="querys.premisesType" placeholder="物业类型"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-cascader
          :options="regions"
          :props="props"
          @change="handleChange"
          clearable></el-cascader>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list">查询</el-button>
        <el-button type="primary" @click="gotoSave">新增</el-button>
      </el-form-item>
    </el-form>
    <hr>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column fixed prop="id" label="楼盘Id" width="150"></el-table-column>
      <el-table-column prop="name" label="楼盘名称" width="120"></el-table-column>
      <el-table-column prop="pic" label="楼盘图片" width="120">
        <template slot-scope="scope">
          <el-image v-if="scope.row.pic!=null&&scope.row.pic!=''"
                    style="width: 100px; height: 100px"
                    :src="scope.row.pic"></el-image>
          <span v-if="scope.row.pic==null || scope.row.pic==''">暂无图片</span>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="地址" width="120"></el-table-column>
      <el-table-column prop="premisesType" label="物业类型" width="300"></el-table-column>
      <el-table-column prop="estate" label="物业管理公司"></el-table-column>
    </el-table>


    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="querys.current"
      :page-sizes="[10, 50, 100, 500]"
      :page-size="querys.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {listhouses, treeRegion} from "@/api/wishu/houses/houses";

export default {
  name: "listView",
  data() {
    return {
      tableData: [],
      regions:[],
      props:{
        value: 'id',
        label: 'name',
      },
      total: 1,
      querys: {
        current: 1,
        size: 10,
        name: '',
        premisesType: '',
        province: '',
        city: '',
        county: '',
      },
    }
  }, created() {
    this.list();
    this.getregion();
  }, methods: {
    gotoSave() {
      this.$router.push("save")
    },
    getregion() {
      treeRegion().then(response => {
        this.regions = response.list;
      })
    },
    list() {
      listhouses(this.querys).then(response => {
        this.tableData = response.list.records;
        this.total = response.list.total;
      })
    },
    handleChange(value) {
      console.log(this.formInline.region);
      this.querys.province=value[1];
      this.querys.city=value[2];
      this.querys.county=value[3];
    },
    handleSizeChange(size) {
      this.querys.size = size;
      this.list();
    },
    handleCurrentChange(page) {
      this.querys.current = page;
      this.list();
    },
  }
}
</script>

<style scoped>

</style>
